package com.chhh.cranelease.mapper;

import com.chhh.cranelease.entity.Base;
import com.chhh.cranelease.entity.FinaceIn;
import com.chhh.cranelease.entity.FinaceOut;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface FinancialManagementMapper {

    @Select("SELECT fo_staffwage, fo_insmoney,fo_repairmoney,sdate,edate  from (select (sum(pl_workdays)*(select workdaymoney from base)+sum(pl_diverdays)*(select diverdaymoney from base)) fo_staffwage from people_log) temp,(select (sum(c_buy)+(count(c_num)*(select insmoney from base))) fo_insmoney from carinfo) temp1,(Select sum(r_cost) fo_repairmoney from repair) temp2,(select startdate as sdate,enddate as edate from base) temp3")
    List<FinaceOut> finceOut();

    @Select("select * from base")
    List<Base> selectAllBase();

    @Update("update base set workdaymoney=#{workdaymoney},diverdaymoney=#{diverdaymoney},insmoney=#{insmoney},tax=#{tax},startdate=#{startdate},enddate=#{enddate} where id=#{id}")
    Integer updateBase(Base base);

    @Select("select fi_before,fi_tax,fi_after,sdate,edate from (select sum(cl_price) fi_before from car_log)temp1,(select (sum(cl_price)-(sum(cl_price)*(select tax from base))) fi_after from car_log) temp2, (select startdate as sdate,enddate as edate from base) temp3,(select (sum(cl_price)*(select tax from base)) fi_tax from car_log) temp4")
    List<FinaceIn> finaceIn();
}